﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Core.Support;
using Microsoft.SharePoint;
using MS.InformationManagement.DAL.DocumentCenter;
using Microsoft.SharePoint.Taxonomy;

namespace MS.InformationManagement.BLL.DocumentPrinter
{
    public class UpdateDeliveryDataCommand : IBaseCommand
    {

         #region fields

        string _libraryName;
        int _documentId;
        string _phone;
        string _address;
        string _email;
        TaxonomyFieldValue _city;

        #endregion

        #region Constructors

        public UpdateDeliveryDataCommand(string libraryName, int documentId, string email, string phone, string address, TaxonomyFieldValue city)
        {
            _libraryName = libraryName;
            _documentId = documentId;      
            _phone = phone;
            _address = address;
            _email = email;
            _city = city;
        }

        #endregion


        public void Execute()
        {
            using (var dc = new DCDocumentCenterDataContext(SPContext.Current.Web.Url))
            {
                var entity = (from item in dc.EnviosDeCorreo
                              where item.IdDocumento == _documentId &&
                                    item.BibliotecaDelDocumento == _libraryName
                              select item).FirstOrDefault();
                entity.City = _city;
                entity.Dirección = _address;
                entity.Email = _email;
                entity.Teléfono = _phone;
                dc.SubmitChanges();
            }

        }

        public void Undo()
        {
        }
    }
}
